import { validateFileList } from '@/util/validate'
const DIC = {
  VAILD: [
    {
      label: '境内',
      value: '1'
    },
    {
      label: '境外',
      value: '2'
    }
  ],
  TYPE: [
    {
      label: '生产厂家',
      value: '1'
    },
    {
      label: '贸易商',
      value: '2'
    },
    {
      label: '代理商',
      value: '3'
    }
  ],
  CAPITAL: [
    {
      label: '国有企业',
      value: '1'
    },
    {
      label: '民营企业',
      value: '2'
    },
    {
      label: '中外合资',
      value: '3'
    },
    {
      label: '外贸独资',
      value: '4'
    },
    {
      label: '上市公司',
      value: '5'
    }
  ]
}
const validateSocial = (rule, value, callback) => {
  if (!/^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/.test(value)) {
    callback(new Error('请输入正确的统一社会信用代码'))
  } else {
    callback()
  }
}
const validatePhone = (rule, value, callback) => {
  if (!/^[1]([3-9])[0-9]{9}$/.test(value)) {
    callback(new Error('请输入正确的手机号格式'))
  } else {
    callback()
  }
}
const validateEmail = (rule, value, callback) => {
  if (!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value)) {
    callback(new Error('请输入正确的邮件格式'))
  } else {
    callback()
  }
}
export const validateArea = (rule, value, callback) => {
  if (Array.isArray(value) && value.length == 0) {
    callback(new Error('请选择区域'))
  } else {
    callback()
  }
}
// baseInfo
export const infoOption = function () {
  return {
    labelWidth: 140,
    submitText: '保存',
    emptyBtn: false,
    submitBtn: !['view'].includes(this.type) && this.btnFlg,
    addDisabled: false,
    detail: ['view'].includes(this.type),
    column: [
      {
        label: '供应商名称',
        span: 8,
        prop: 'supplierName',
        maxlength: 100,
        rules: [
          {
            required: true,
            message: '请输入供应商名称',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '供应商简称',
        maxlength: 100,
        span: 8,
        prop: 'supplierShortName'
      },
      {
        label: '成立日期',
        span: 8,
        prop: 'establishDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        rules: [
          {
            required: true,
            message: '请输入成立日期',
            trigger: 'change'
          }
        ]
      },
      {
        label: '境内外关系',
        span: 8,
        prop: 'outbound',
        type: 'select',
        dicUrl: '/api/blade-system/dict-biz/dictionary?code=supplier_outbound',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        rules: [
          {
            required: true,
            message: '请选择境内外关系',
            trigger: 'change'
          }
        ]
      },
      {
        label: '统一社会信用代码',
        // labelWidth: 150,
        maxlength: 50,
        span: 8,
        prop: 'socialCreditCode',
        rules: [
          {
            required: true,
            message: '请输入统一社会信用代码',
            trigger: 'blur'
          },
          { validator: validateSocial, trigger: 'blur' }
        ]
      },
      {
        label: '境外识别码',
        maxlength: 50,
        span: 8,
        prop: 'outsideIdentifier',
        display: false
      },
      {
        label: '集团名称',
        span: 8,
        maxlength: 50,
        prop: 'groupName'
      },
      {
        label: '公司类型',
        span: 8,
        prop: 'companyType',
        type: 'select',
        dicUrl: '/api/blade-system/dict-biz/dictionary?code=supplier_company_type',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        rules: [
          {
            required: true,
            message: '请选择公司类型',
            trigger: 'change'
          }
        ]
      },
      {
        label: '所属行业',
        span: 8,
        prop: 'capitalType',
        type: 'select',
        dicUrl: '/api/blade-system/dict-biz/dictionary?code=supplier_industry_type',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        rules: [
          {
            required: true,
            message: '请选择所属行业',
            trigger: 'change'
          }
        ]
      },
      {
        label: '公司网址',
        span: 8,
        maxlength: 50,
        prop: 'website'
      },
      {
        label: '区域',
        span: 8,
        prop: 'areas',
        type: 'cascader',
        props: [
          {
            label: 'label',
            value: 'value',
            children: 'children'
          }
        ],
        dicData: window.getRegionData(),
        rules: [
          { required: true, type: 'array', validator: validateArea, trigger: 'blur' }
          // {
          //   type: 'array',
          //   required: true,
          //   message: '请输入区域',
          //   trigger: ['change','blur']
          // }
        ]
      },
      {
        label: '注册地址',
        span: 8,
        maxlength: 50,
        prop: 'registerAddr',
        rules: [
          {
            required: true,
            message: '请输入注册地址',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '联系人',
        span: 8,
        maxlength: 50,
        prop: 'contact',
        rules: [
          {
            required: true,
            message: '请输入联系人',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '联系人职务',
        span: 8,
        maxlength: 50,
        prop: 'contactPost'
      },
      {
        label: '手机号码',
        span: 8,
        maxlength: 50,
        prop: 'phone',
        rules: [
          {
            required: true,
            message: '请输入手机号码',
            trigger: 'blur'
          },
          { validator: validatePhone, trigger: 'blur' }
        ]
      },
      {
        label: '邮件',
        span: 8,
        maxlength: 50,
        prop: 'email',
        rules: [
          {
            required: true,
            message: '请输入邮件',
            trigger: 'blur'
          },
          { validator: validateEmail, trigger: 'blur' }
        ]
      },
      {
        label: '固定电话',
        span: 8,
        maxlength: 50,
        prop: 'telephone'
      },
      {
        label: '厂房面积',
        span: 8,
        maxlength: 50,
        prop: 'plantArea'
      },
      {
        label: '总人数',
        span: 8,
        maxlength: 50,
        prop: 'totalNumber'
      },
      {
        label: '经营范围',
        span: 24,
        maxlength: 500,
        prop: 'busScope',
        type: 'textarea',
        minRows: 5,
        maxRows: 10
      },
      {
        label: '公司简介',
        span: 24,
        maxlength: 500,
        prop: 'companyProfile',
        type: 'textarea',
        minRows: 5,
        maxRows: 10
      },
      {
        label: '营业执照',
        span: 24,
        formslot: true,
        prop: 'attachVOS',
        type: 'upload',
        rules: [
          {
            required: true,
            message: '请上传营业执照',
            validator: validateFileList,
            trigger: 'blur'
          }
        ]
      }
    ]
  }
}
